﻿using System;
using System.Configuration;
using System.Linq;
using Controllers;

namespace Web
{
    public partial class EmpContactEdit : System.Web.UI.Page
    {
        ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
        protected Employee employee;
        protected void Page_Load(object sender, EventArgs e)
        {
            string empId = Request.QueryString["empId"];
            int id;
            if (empId != null)
            {
                id = int.Parse(empId);
            }
            else
            {
                EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
                id = ebi.Id;
            }
            employee = ctx.Employees.Single(r => r.Id == id);
            if (!IsPostBack)
            {
                Mobile.Value = employee.Mobile;
                TelExt.Value = employee.TelExt;
                ShortNo.Value = employee.ShortNo.ToString();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            employee.Mobile = Mobile.Value;
            employee.TelExt = TelExt.Value;
            if(!string.IsNullOrEmpty(ShortNo.Value))
            {
                employee.ShortNo = int.Parse(ShortNo.Value);
            }
            ctx.SubmitChanges();
            Response.Write("<script>window.returnValue='Succeed';window.close();</script>");
        }
    }
}